package main

import (
	"log"
	"os"
	"tt_erp/common"
	"tt_erp/router"

	"github.com/spf13/viper"
)

func IntiConfig() {
	// 获取当前文件目录
	workDir, _ := os.Getwd()
	viper.SetConfigName("application")
	viper.SetConfigType("yml")
	viper.AddConfigPath(workDir + "/config")
	err := viper.ReadInConfig()
	if err != nil {
		log.Println(err)
	}
}

func main() {
	// 读取配置项
	IntiConfig()
	// 连接数据库
	db := common.InitDB()
	sqlDB, _ := db.DB()
	defer sqlDB.Close()
	// 路由
	r := router.Router()
	port := viper.GetString("server.port")
	r.Run(":" + port) //Listen and server on localhost:666 (window)
}
